#!/bin/bash
set -x

IMPALA_HOME=/opt/impala/current
IMPALA_BUILD=/app/impala-3.4.0

# if exist the dest directory then clear it.
if [ -d "${IMPALA_BUILD}" ]; then
        rm -rf ${IMPALA_BUILD}/*
else
        mkdir -p ${IMPALA_BUILD}
fi

mkdir -p ${IMPALA_BUILD}/conf/
mkdir -p ${IMPALA_BUILD}/sbin/
mkdir -p ${IMPALA_BUILD}/lib/
mkdir -p ${IMPALA_BUILD}/toolchain/
mkdir -p ${IMPALA_BUILD}/toolchain/kudu-4ed0dbbd1/release/lib64
mkdir -p ${IMPALA_BUILD}/www/
mkdir -p ${IMPALA_BUILD}/impala-shell/
mkdir -p ${IMPALA_BUILD}/bin/
mkdir -p ${IMPALA_BUILD}/logs/

cp -a ${IMPALA_HOME}/be/build/release/service/{catalogd,statestored,impalad,libfesupport.so} ${IMPALA_BUILD}/bin/
cp -a ${IMPALA_HOME}/fe/target/dependency/*.jar ${IMPALA_BUILD}/lib/
cp -a ${IMPALA_HOME}/fe/target/impala-frontend-0.1-SNAPSHOT.jar ${IMPALA_BUILD}/lib/
cp -rp ${IMPALA_HOME}/toolchain/gcc-4.9.2 ${IMPALA_BUILD}/toolchain
cp -rp ${IMPALA_HOME}/toolchain/kudu-4ed0dbbd1/release/lib64/* ${IMPALA_BUILD}/toolchain/kudu-4ed0dbbd1/release/lib64
cp -R ${IMPALA_HOME}/www/* ${IMPALA_BUILD}/www/
cp -R ${IMPALA_HOME}/shell/build/impala-shell-3.4.0-RELEASE/* ${IMPALA_BUILD}/impala-shell/
cp -R ${IMPALA_HOME}/shell/build/impala-shell-3.4.0-RELEASE/impala-shell ${IMPALA_BUILD}/bin/
sed -i "s|^SCRIPT_DIR.*$|SCRIPT_DIR=${IMPALA_BUILD}/impala-shell|g" ${IMPALA_BUILD}/bin/impala-shell

cp -a ./conf/impala.conf ${IMPALA_BUILD}/conf

cp -a ./jar/mysql-connector-java.jar ${IMPALA_BUILD}/lib

cp -r ./sbin/* ${IMPALA_BUILD}/sbin
chmod +x sbin/run-impala-daemon

echo "Finished"




